﻿using Cl.Model.DataBaseEntityDtos.User.Permissions;
using Cl.Model.Results;
using Cl.Service.Service.User;
using Cl.Service.Service.User.Permissions;
using Cl.Utils;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Cl.WebApi.Areas.Admin.Users
{
    /// <summary>
    /// 权限管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.AdminGroup)]
    public class PermissionController : BaseController
    {
        private IPermissionService _permissionService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public PermissionController(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }

        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultInfoModel GetMenusList()
        {
            var data = _permissionService.GetMenusList();

            return GetResult.Success("Success", data);
        }

        /// <summary>
        /// 获取用户菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultInfoModel GetUserMenus()
        {

            List<PermissionOutDto> result = new();
            if (GlobalUserManager.Account == "ChaoJiAdmin")
            {
                result = _permissionService.GetMenusList();
            }
            else
            {
                result = _permissionService.GetUserMenus(GlobalUserManager.UserId);
            }

            return GetResult.Success("Success", result);
        }
    }
}
